package com.zxj.schoolxianyu.controller;

import com.zxj.schoolxianyu.entity.message;
import com.zxj.schoolxianyu.entity.userData;
import com.zxj.schoolxianyu.entity.userRegiste;
import com.zxj.schoolxianyu.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/users")
public class userController {
    @Autowired
    private userRegisteService userRegisteService;
    @Autowired
    private userLoginService userLoginService;
    @Autowired
    private userDataUpService dataUpService;
    @Autowired
    private GetUserDataService getUserDataService;
    @Autowired
    private getMyPostService getMyPostService;
    @Autowired
    private getSelledService getSelledService;
    @Autowired
    private getBoughtService getBoughtService;
    @Autowired
    private followService followService;
    @Autowired
    private getFollowStateService getFollowStateService;
    @Autowired
    private unfollowService unfollowService;
    @Autowired
    private getFollowingGoodsService getFollowingGoodsService;
    @Autowired
    private addBrowseHisService addBrowseHisService;
    @Autowired
    private getBrowseHisGoodsService getBrowseHisGoodsService;
    @Autowired
    private getCollectStateService getCollectStateService;
    @Autowired
    private collectService collectService;
    @Autowired
    private uncollectService uncollectService;
    @Autowired
    private getCollectedGoodsService getCollectedGoodsService;
    @Autowired
    private createConversationService createConversationService;
    @Autowired
    private chatService chatService;
    @Autowired
    private chatHisService chatHisService;
    @Autowired
    private getChatListService getChatListService;

    @PostMapping("/registe")
    public String registe(@RequestBody userRegiste user) {
        return userRegisteService.Registe(user);
    }

    @PostMapping("/login")
    public String login(@RequestBody userRegiste user) {
        return userLoginService.Login(user);
    }

    @PostMapping("/dataUp")
    public String dataUp(@RequestBody userData userdata) {
        return dataUpService.userDataUp(userdata);
    }

    @GetMapping("/data")
    public userData getdata(@RequestParam String username) {
        userData a = new userData();
        a.username = username;
        return getUserDataService.userData(a);
    }

    @GetMapping("/getMyPost")
    public String getMyPost(@RequestParam String username) {
        return getMyPostService.getMyPosts(username);
    }

    @GetMapping("/getSelled")
    public String getSelled(@RequestParam String username) {
        return getSelledService.getSelled(username);
    }

    @GetMapping("/getBought")
    public String getBought(@RequestParam String username) {
        return getBoughtService.getBought(username);
    }

    @GetMapping("/getfollowstate")
    public String getfollowstate(@RequestParam String fromusername, @RequestParam String tousername) {
        return getFollowStateService.getFollowState(fromusername, tousername);
    }

    @PostMapping("/follow")
    public String follow(@RequestParam String fromusername, @RequestParam String tousername) {
        return followService.follow(fromusername, tousername);
    }

    @PostMapping("/unfollow")
    public String unfollow(@RequestParam String fromusername, @RequestParam String tousername) {
        return unfollowService.unfollow(fromusername, tousername);
    }

    @GetMapping("/getFollowingGoods")
    public String getFollowingGoods(@RequestParam String username) {
        return getFollowingGoodsService.getFollowingGoods(username);
    }

    @PostMapping("/addhis")
    public String addhis(@RequestParam String username, @RequestParam Integer goodsid) {
        return addBrowseHisService.addHis(username, goodsid);
    }

    @GetMapping("/getbrosehis")
    public String getbrosehis(@RequestParam String username) {
        return getBrowseHisGoodsService.getHisGoods(username);
    }

    @GetMapping("/getcollectstate")
    public String getcollectstate(@RequestParam String username, @RequestParam Integer goodsid) {
        System.out.println(getCollectStateService.getState(username, goodsid));
        return getCollectStateService.getState(username, goodsid);
    }

    @PostMapping("/collect")
    public String collect(@RequestParam String username, @RequestParam Integer goodsid) {
        System.out.println(collectService.collect(username, goodsid));
        return collectService.collect(username, goodsid);
    }

    @PostMapping("/uncollect")
    public String uncollect(@RequestParam String username, @RequestParam Integer goodsid) {
        return uncollectService.uncollect(username, goodsid);
    }

    @GetMapping("/getcollectedgoods")
    public String getcollectedgoods(@RequestParam String username) {
        return getCollectedGoodsService.getCollectedGoods(username);
    }

    @PostMapping("/chat")
    public String chat(@RequestBody message m) {
        return chatService.chat(m);
    }

    @GetMapping("/chathis")
    public String chathis(@RequestParam Integer conversationid) {
        return chatHisService.ChatHis(conversationid);
    }

    @GetMapping("/createC")
    public String createC(@RequestParam String user1,@RequestParam String user2){
        return createConversationService.createConversation(user1,user2);
    }

    @GetMapping("/chatlist")
    public String chatlist(@RequestParam String user){
        return getChatListService.ChatList(user);
    }
}